function [C,Px] = gmm_predict(X, model)
% Expectation-Maximization iteration implementation of
% Gaussian Mixture Predict Model.
%
% [model] = gmm(X, K_OR_CENTROIDS)
% [C,Px] = gmm_predict(X, model)

 
    [N, ~] = size(X);
    pMiu = model.Miu;
    pSigma = model.Sigma;
    K = length(model.Pi);
    
    Px = calc_prob();
    [~,C] = max(Px');
    C = C';
 
    function Px = calc_prob()
        Px = zeros(N, K);
        for k = 1:K
          Px(:,k) = mvnpdf(X,pMiu(k,:),pSigma(:,:,k));
        end
    end
end